﻿using System;
using System.Collections.Generic;
using Extreme.SPFramework.BusinessLogicTemplate.Entities;
using Extreme.SPFramework.BusinessLogicTemplate.Interfaces;
using Extreme.SPFramework.DependencyInjection;
using Extreme.SPFramework.DomainModel;

namespace Extreme.SPFramework.BusinessLogicTemplate.Services
{
    /// <summary>
    /// My service
    /// </summary>
    [Service(typeof(IMyService))]
    public class MyService : IMyService
    {
        private IRepository<MyEntity> repository;

        /// <summary>
        /// Creates new instance (use with dependency injection)
        /// </summary>
        public MyService(IRepository<MyEntity> repository)
        {
            this.repository = repository;
        }

        /// <summary>
        /// Saves entity
        /// </summary>
        public void Save(MyEntity entity)
        {
            if (entity == null)
                throw new ArgumentNullException("entity");
            repository.SaveItem(entity);
        }

        /// <summary>
        /// Gets all entities
        /// </summary>
        public List<MyEntity> GetAllItems()
        {
            return repository.GetAllItems();
        }
    }
}
